#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

ll pow_mod(ll a, ll b, ll c){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b&1) ans = ans*a%c;
        a = a*a%c;
        b>>=1;
    }
    return ans;
}

int main() {
    int t,Case = 0;
    ll n,k;
    cin>>t;
    while(t--) {
        scanf("%lld %lld",&n,&k);
        ll ans = pow_mod(2,n,mod)-1;
        ll num = n;
        for(int i=2;i<k;++i) {
            ans = ((ans-num+mod)%mod+mod)%mod;
            num = (num*(n-i+1)%mod)*(pow_mod(i,mod-2,mod))%mod;
        }
        ans = ((ans-num+mod)%mod+mod)%mod;

        printf("Case #%d: %lld\n",++Case, ans%mod);
    }
    return 0;
}
 